package com.usefullc.english.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.english.domain.ContentRead;
import com.usefullc.english.mapper.ContentReadMapper;
import com.usefullc.english.query.ContentReadQuery;
import com.usefullc.english.vo.ContentReadVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 内容阅读服务类
 * @author: 星空
 * @date: 2022-08-07
 */
@Service
public class ContentReadService extends AbstractBizService<ContentReadMapper, ContentRead, ContentReadQuery> {


    @Override
    protected QueryWrapper<ContentRead> getQueryWrapper(ContentReadQuery query) {
        QueryWrapper<ContentRead> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<ContentReadVo> findVoByPage(ContentReadQuery query){
        Pager<ContentRead> page = this.findByPage(query);
        Pager<ContentReadVo> newPage = new Pager<>(page);
        List<ContentRead> dataList = page.getDataList();
        List<ContentReadVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (ContentRead contentRead : dataList) {
            ContentReadVo contentReadVo = BeanUtils.beanCopy(contentRead, ContentReadVo.class);
            newDataList.add(contentReadVo);
        }
        return newPage;
    }


}
